package com.woniu.gf.pawn.store.client;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

/**
 * @BelongsProject: gf-pawn-system
 * @BelongsPackage: com.woniu.gf.pawn.management.client
 * @Author: wu wei
 * @CreateTime: 2020-10-16 20:37
 * @Description:
 */
@Component
public class TokenClient implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate template) {
        ServletRequestAttributes sra =(ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        String token = sra.getRequest().getHeader("token");
        if (StringUtils.isNotEmpty(token)) {
            template.header("token",token);
        }
    }
}
